package com.sduept.nwld.dataserver.manager.statistics;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import org.apache.commons.lang3.StringUtils;

import com.sduept.core.dao.SuperDAO;
import com.sduept.nwld.dataserver.model.countanalyse.FaultFastRemove;
import com.sduept.nwld.dataserver.model.countanalyse.ProtectCorrectAct;

@Service
public class ProtectKpiManager {

	@Autowired
	private SuperDAO dao;
	
	/**
	 * **********************保护动作正确率**********************
	 */
	public List<ProtectCorrectAct> getAllProtectCorrectActs() {
		return dao.findAll(ProtectCorrectAct.class);
	}
	
	public ProtectCorrectAct createOrUpdate(ProtectCorrectAct protectCorrectAct) {
		return dao.createOrUpdate(protectCorrectAct, ProtectCorrectAct.class);
	}
	
	public void saveProtectCorrectAct(List<ProtectCorrectAct> list) throws SQLException {
		dao.persistentBatch(ProtectCorrectAct.class, list);
	}
	
	public void deleteProtectCorrectActById(String id) {
		dao.delete(id, ProtectCorrectAct.class);
	}
	
	public void deleteAllProtectCorrectAct() {
		dao.deleteAll(ProtectCorrectAct.class);
	}
	@Deprecated
	public void deleteProtectCorrectAct(Integer year,Integer month) {
		if(null != month) {
			if(0==month) {
				// 删除当年1-12月份的数据
				dao.delete(ProtectCorrectAct.class,"year=? and month is not null", year);
			} else {
				dao.delete(ProtectCorrectAct.class,"year=? and month=?", year,month);
			}
		} else if(null == month){
			// 删除当年 month为null的数据
			dao.delete(ProtectCorrectAct.class,"year=? and month is null", year);
		}
	}
	
	/**
	 * 根据年、月、单位类型、是否覆盖删除
	 * @param year
	 * @param month
	 * @param unitType
	 * @param covered
	 */
	public void deleteProtectCorrectAct(Integer year, Integer month, int unitType, boolean covered) {
		if(covered) {//覆盖
			if(null != month) {
				if(0==month) {
					// 删除当年1-12月份的数据
					dao.delete(ProtectCorrectAct.class,"year=? and month is not null and unitType=?", year, unitType);
				} else {
					dao.delete(ProtectCorrectAct.class,"year=? and month=? and unitType=?", year,month,unitType);
				}
			} else if(null == month){
				// 删除当年 month为null的数据
				dao.delete(ProtectCorrectAct.class,"year=? and month is null and unitType=?", year,unitType);
			}
		}else {//不覆盖
			if(null != month) {
				if(0==month) {
					// 删除当年1-12月份的数据
					dao.delete(ProtectCorrectAct.class,"year=? and month is not null and unitType=? and status = 0", year,unitType);
				} else {
					dao.delete(ProtectCorrectAct.class,"year=? and month=? and unitType=? and status = 0", year,month,unitType);
				}
			} else if(null == month){
				// 删除当年 month为null的数据
				dao.delete(ProtectCorrectAct.class,"year=? and month is null and unitType=? and status = 0", year,unitType);
			}
		}
	}
	/**
	 * 查询月度与年度数据
	 * @param year
	 * @param month 为null,查询当年的所有数据（month=null,month=1-12）；不为null，查询指定月份的数据
	 * @param voltage
	 * @return
	 */
	public List<ProtectCorrectAct> queryYearData(Integer year, Integer month,Integer voltage) {
		//查询需要的数据
		List<Object> params = new ArrayList<>();
		String sql = "select * from t_count_protect_correct_act where 1=1 ";
		if(voltage != null) {
			sql += " and voltage = ? ";
			params.add(voltage);
		}
		if(year != null) {
			sql += " and year = ? ";
			params.add(year);
		}
		if(month != null) {
			sql += " and month = ? ";
			params.add(month);
		}
		List<ProtectCorrectAct> list = dao.nativeQuery(sql, params.toArray(), ProtectCorrectAct.class);
		return list;
	}
	/**
	 * 查询月度数据、年指标数据
	 * @param year
	 * @param month 为null,查询年指标数据（month=null,month=1-12）；不为null，查询指定月份的数据
	 * @param voltage
	 * @param unitType
	 * @return
	 */
	public List<ProtectCorrectAct> queryYearData(Integer year, Integer month,Integer voltage, int unitType) {
		//查询需要的数据
		List<Object> params = new ArrayList<>();
		String sql = "select * from t_count_protect_correct_act where 1=1 ";
		if(voltage != null) {
			sql += " and voltage = ? ";
			params.add(voltage);
		}
		if(year != null) {
			sql += " and year = ? ";
			params.add(year);
		}
		if(month != null) {
			sql += " and month = ? ";
			params.add(month);
		}else {
			sql += " and month is null ";
		}
		sql += " and unit_type = ? ";
		params.add(unitType);
		List<ProtectCorrectAct> list = dao.nativeQuery(sql, params.toArray(), ProtectCorrectAct.class);
		return list;
	}

	/**
	 * 查询月度数据、年指标数据
	 * @param year
	 * @param month 为null,查询年指标数据（month=null,month=1-12）；不为null，查询指定月份的数据
	 * @param voltage
	 * @param unitType 单位类型
	 * @param unit 单位名称
	 * @return
	 */
	public List<ProtectCorrectAct> queryYearData(Integer year, Integer month,Integer voltage, int unitType, List<String> unit) {
		//查询需要的数据
		List<Object> params = new ArrayList<>();
		String sql = "select * from t_count_protect_correct_act where 1=1 ";
		if(voltage != null) {
			sql += " and voltage = ? ";
			params.add(voltage);
		}
		if(year != null) {
			sql += " and year = ? ";
			params.add(year);
		}
		if(month != null) {
			sql += " and month = ? ";
			params.add(month);
		}else {
			sql += " and month is null ";
		}
		sql += " and unit_type = ? ";
		params.add(unitType);
		//TODO params中有()时，转成array，查询时有异常。遂遍历去除非勾选数据
//		if(unit != null && unit.length > 0) {
//			sql += " and sub_company in ? ";
//			StringBuilder sb = new StringBuilder();
//			for(String u : unit) {
//				sb.append(",'").append(u).append("'");
//			}
//			params.add("(" + sb.toString().substring(1) + ")");
//		}
		List<ProtectCorrectAct> list = dao.nativeQuery(sql, params.toArray(), ProtectCorrectAct.class);
		List<ProtectCorrectAct> dataList = new ArrayList<ProtectCorrectAct>();//返回数据
		for(ProtectCorrectAct protectCorrectAct : list) {
			if(unit.contains(protectCorrectAct.getSubCompany())) {
				dataList.add(protectCorrectAct);
			}
		}
		return dataList;
	}
	
	/**
	 * 查询月度数据
	 * @param year 为null 返回长度为0的列表
	 * @param month 为null，查询本年1-12月份的数据；不为null，查询指定月份的数据
	 * @param subcompany 为null则查询所有公司
	 * @return
	 */
	public List<ProtectCorrectAct> queryMonthProtectCorrectActByCondition(Integer year,Integer month,String subcompany,Integer voltage) {
		List<ProtectCorrectAct> ret = new ArrayList<>();
		if(year == null)
			return ret;
		List<Object> values = new ArrayList<>();
		String sql = "year = ? ";
		values.add(year);
		if(month != null) {
			sql += " and month = ? ";
			values.add(month);
		} else {
			sql += " and month is not null ";
		}
		if(StringUtils.isNotEmpty(subcompany)) {
			sql += " and subCompany = ? ";
			values.add(subcompany);
		}
		if(voltage != null) {
			sql += " and voltage = ? ";
			values.add(voltage);
		}
		sql += " order by month";
		ret = dao.findByCondition(ProtectCorrectAct.class, sql, values.toArray());
		return ret;
	}
	/**
	 * 查询月度数据
	 * @param year 为null 返回长度为0的列表
	 * @param month 为null，查询本年1-12月份的数据；不为null，查询指定月份的数据
	 * @param subcompany 为null则查询所有公司
	 * @return
	 */
	public List<ProtectCorrectAct> queryMonthProtectCorrectActByCondition(Integer year, Integer month, String subcompany, 
		Integer voltage, int unitType) {
		List<ProtectCorrectAct> ret = new ArrayList<>();
		if(year == null)
			return ret;
		List<Object> values = new ArrayList<>();
		String sql = "year = ? ";
		values.add(year);
		if(month != null) {
			sql += " and month = ? ";
			values.add(month);
		} else {
			sql += " and month is not null ";
		}
		if(StringUtils.isNotEmpty(subcompany)) {
			sql += " and subCompany = ? ";
			values.add(subcompany);
		}
		if(voltage != null) {
			sql += " and voltage = ? ";
			values.add(voltage);
		}
		sql += " and unit_type = ? ";
		values.add(unitType);
		sql += " order by month";
		ret = dao.findByCondition(ProtectCorrectAct.class, sql, values.toArray());
		return ret;
	}
	/**
	 * 查询月度数据
	 * @param year 为null 返回长度为0的列表
	 * @param month 为null，查询本年1-12月份的数据；不为null，查询指定月份的数据
	 * @param subcompany 为null则查询所有公司
	 * @return
	 */
	public List<ProtectCorrectAct> queryMonthProtectCorrectActByCondition(Integer year, Integer month, String subcompany, 
		Integer voltage, int unitType, List<String> unit) {
		List<ProtectCorrectAct> ret = new ArrayList<>();
		if(year == null)
			return ret;
		List<Object> values = new ArrayList<>();
		String sql = "year = ? ";
		values.add(year);
		if(month != null) {
			sql += " and month = ? ";
			values.add(month);
		} else {
			sql += " and month is not null ";
		}
		if(StringUtils.isNotEmpty(subcompany)) {
			sql += " and subCompany = ? ";
			values.add(subcompany);
		}
		if(voltage != null) {
			sql += " and voltage = ? ";
			values.add(voltage);
		}
		sql += " and unit_type = ? ";
		values.add(unitType);
		sql += " order by month";
		ret = dao.findByCondition(ProtectCorrectAct.class, sql, values.toArray());
		List<ProtectCorrectAct> dataList = new ArrayList<ProtectCorrectAct>();//返回数据
		for(ProtectCorrectAct protectCorrectAct : ret) {
			if(unit.contains(protectCorrectAct.getSubCompany())) {
				dataList.add(protectCorrectAct);
			}
		}
		return dataList;
	}
	/**
	 * 查询年度数据（即month=null的记录）
	 * @param year 为null返回长度为0的列表
	 * @param subcompany 为null查询所有公司
	 * @return
	 */
	public List<ProtectCorrectAct> queryYearProtectCorrectActByCondition(Integer year,String subcompany, Integer voltage) {
		List<ProtectCorrectAct> ret = new ArrayList<>();
		if(year == null)
			return ret;
		List<Object> values = new ArrayList<>();
		String sql = "year = ? and month is null ";
		values.add(year);
		if(StringUtils.isNotEmpty(subcompany)) {
			sql += " and subCompany = ? ";
			values.add(subcompany);
		}
		if(voltage != null) {
			sql += " and voltage = ? ";
			values.add(voltage);
		}
		sql += " order by year";
		ret = dao.findByCondition(ProtectCorrectAct.class, sql, values.toArray());
		return ret;
	}
	/**
	 * 查询年度数据（即month=null的记录）
	 * @param year 为null返回长度为0的列表
	 * @param subcompany 为null查询所有公司
	 * @return
	 */
	public List<ProtectCorrectAct> queryYearProtectCorrectActByCondition(Integer year,String subcompany, Integer voltage, 
		int unitType) {
		List<ProtectCorrectAct> ret = new ArrayList<>();
		if(year == null)
			return ret;
		List<Object> values = new ArrayList<>();
		String sql = "year = ? and month is null ";
		values.add(year);
		if(StringUtils.isNotEmpty(subcompany)) {
			sql += " and subCompany = ? ";
			values.add(subcompany);
		}
		if(voltage != null) {
			sql += " and voltage = ? ";
			values.add(voltage);
		}
		sql += " and unit_type = ? ";
		values.add(unitType);
		sql += " order by year";
		ret = dao.findByCondition(ProtectCorrectAct.class, sql, values.toArray());
		return ret;
	}
	/**
	 * 查询年度数据（即month=null的记录）
	 * @param year 为null返回长度为0的列表
	 * @param subcompany 为null查询所有公司
	 * @param voltage
	 * @param unitType 单位类型
	 * @param unit 单位名称
	 * @return
	 */
	public List<ProtectCorrectAct> queryYearProtectCorrectActByCondition(Integer year,String subcompany, Integer voltage, 
		int unitType, List<String> unit) {
		List<ProtectCorrectAct> ret = new ArrayList<>();
		if(year == null)
			return ret;
		List<Object> values = new ArrayList<>();
		String sql = "year = ? and month is null ";
		values.add(year);
		if(StringUtils.isNotEmpty(subcompany)) {
			sql += " and subCompany = ? ";
			values.add(subcompany);
		}
		if(voltage != null) {
			sql += " and voltage = ? ";
			values.add(voltage);
		}
		sql += " and unit_type = ? ";
		values.add(unitType);
		sql += " order by year";
		ret = dao.findByCondition(ProtectCorrectAct.class, sql, values.toArray());
		List<ProtectCorrectAct> dataList = new ArrayList<ProtectCorrectAct>();//返回数据
		for(ProtectCorrectAct protectCorrectAct : ret) {
			if(unit.contains(protectCorrectAct.getSubCompany())) {
				dataList.add(protectCorrectAct);
			}
		}
		return dataList;
	}
	
	/**
	 * **********************故障快速切除率**********************
	 */
	public List<FaultFastRemove> getAllFaultFastRemoves() {
		return dao.findAll(FaultFastRemove.class);
	}
	
	public FaultFastRemove createOrUpdate(FaultFastRemove faultFastRemove) {
		return dao.createOrUpdate(faultFastRemove, FaultFastRemove.class);
	}
	
	public void deleteFaultFastRemoveById(String id) {
		dao.delete(id, FaultFastRemove.class);
	}
	
	public void deleteAllFaultFastRemove() {
		dao.deleteAll(FaultFastRemove.class);
	}
	@Deprecated
	public void deleteFaultFastRemove(Integer year,Integer month) {
		if(null != month) {
			if(0==month) {
				// 删除当年1-12月份的数据
				dao.delete(FaultFastRemove.class,"year=? and month is not null", year);
			} else {
				dao.delete(FaultFastRemove.class,"year=? and month=?", year,month);
			}
		} else if(null == month){
			// 删除当年 month为null的数据
			dao.delete(FaultFastRemove.class,"year=? and month is null", year);
		}
	}
	
	/**
	 * 根据年、月、单位类型、是否覆盖删除
	 * @param year
	 * @param month
	 * @param unitType
	 * @param covered
	 */
	public void deleteFaultFastRemove(Integer year,Integer month, int unitType, boolean covered) {
		if(covered) {//覆盖
			if(null != month) {
				if(0==month) {
					// 删除当年1-12月份的数据
					dao.delete(FaultFastRemove.class,"year=? and month is not null and unitType=?", year,unitType);
				} else {
					dao.delete(FaultFastRemove.class,"year=? and month=? and unitType=?", year,month,unitType);
				}
			} else if(null == month){
				// 删除当年 month为null的数据
				dao.delete(FaultFastRemove.class,"year=? and month is null and unitType=?", year,unitType);
			}
		}else {//不覆盖
			if(null != month) {
				if(0==month) {
					// 删除当年1-12月份的数据
					dao.delete(FaultFastRemove.class,"year=? and month is not null and unitType=? and status = 0", year,unitType);
				} else {
					dao.delete(FaultFastRemove.class,"year=? and month=? and unitType=? and status = 0", year,month,unitType);
				}
			} else if(null == month){
				// 删除当年 month为null的数据
				dao.delete(FaultFastRemove.class,"year=? and month is null and unitType=? and status = 0", year,unitType);
			}
		}
	}
	
	/**
	 * 查询月度与年度数据
	 * @param year
	 * @param month 为null,查询当年的所有数据（month=null,month=1-12）；不为null，查询指定月份的数据
	 * @param voltage
	 * @return
	 */
	public List<FaultFastRemove> queryRemoveYearData(Integer year, Integer month,Integer voltage) {
		//查询需要的数据
		List<Object> params = new ArrayList<>();
		String sql = "select * from t_count_fault_fast_remove where 1=1 ";
		if(voltage != null) {
			sql += " and voltage = ? ";
			params.add(voltage);
		}
		if(year != null) {
			sql += " and year = ? ";
			params.add(year);
		}
		if(month != null) {
			sql += " and month = ? ";
			params.add(month);
		}
		List<FaultFastRemove> list = dao.nativeQuery(sql, params.toArray(), FaultFastRemove.class);
		return list;
	}
	/**
	 * 查询月度数据、年指标数据
	 * @param year
	 * @param month 为null,查询年指标数据（month=null,month=1-12）；不为null，查询指定月份的数据
	 * @param voltage
	 * @param unitType
	 * @return
	 */
	public List<FaultFastRemove> queryRemoveYearData(Integer year, Integer month, Integer voltage, int unitType) {
		//查询需要的数据
		List<Object> params = new ArrayList<>();
		String sql = "select * from t_count_fault_fast_remove where 1=1 ";
		if(voltage != null) {
			sql += " and voltage = ? ";
			params.add(voltage);
		}
		if(year != null) {
			sql += " and year = ? ";
			params.add(year);
		}
		if(month != null) {
			sql += " and month = ? ";
			params.add(month);
		}else {
			sql += " and month is null ";
		}
		sql += " and unit_type = ? ";
		params.add(unitType);
		List<FaultFastRemove> list = dao.nativeQuery(sql, params.toArray(), FaultFastRemove.class);
		return list;
	}
	/**
	 * 查询月度数据、年指标数据
	 * @param year
	 * @param month 为null,查询年指标数据（month=null,month=1-12）；不为null，查询指定月份的数据
	 * @param voltage
	 * @param unitType 单位类型
	 * @param unit 单位名称
	 * @return
	 */
	public List<FaultFastRemove> queryRemoveYearData(Integer year, Integer month, Integer voltage, int unitType, List<String> unit) {
		//查询需要的数据
		List<Object> params = new ArrayList<>();
		String sql = "select * from t_count_fault_fast_remove where 1=1 ";
		if(voltage != null) {
			sql += " and voltage = ? ";
			params.add(voltage);
		}
		if(year != null) {
			sql += " and year = ? ";
			params.add(year);
		}
		if(month != null) {
			sql += " and month = ? ";
			params.add(month);
		}else {
			sql += " and month is null ";
		}
		sql += " and unit_type = ? ";
		params.add(unitType);
		//TODO params中有()时，转成array，查询时有异常。遂遍历去除非勾选数据
//		if(unit != null && unit.length > 0) {
//			sql += " and sub_company in ? ";
//			StringBuilder sb = new StringBuilder();
//			for(String u : unit) {
//				sb.append(",'").append(u).append("'");
//			}
//			params.add("(" + sb.toString().substring(1) + ")");
//		}
		List<FaultFastRemove> list = dao.nativeQuery(sql, params.toArray(), FaultFastRemove.class);
		List<FaultFastRemove> dataList = new ArrayList<FaultFastRemove>();//返回数据
		for(FaultFastRemove faultFastRemove : list) {
			if(unit.contains(faultFastRemove.getSubCompany())) {
				dataList.add(faultFastRemove);
			}
		}
		return dataList;
	}
	/**
	 * 查询月度数据
	 * @param year 为null 返回长度为0的列表
	 * @param month 为null则查询本年所有月度数据
	 * @param subcompany 为null则查询所有公司
	 * @return
	 */
	public List<FaultFastRemove> queryMonthFaultFastRemoveByCondition(Integer year,Integer month,String subcompany,Integer voltage) {
		List<FaultFastRemove> ret = new ArrayList<>();
		if(year == null)
			return ret;
		List<Object> values = new ArrayList<>();
		String sql = "year = ? ";
		values.add(year);
		if(month != null) {
			sql += " and month = ? ";
			values.add(month);
		}else {
			sql += " and month is not null ";
		}
		if(StringUtils.isNotEmpty(subcompany)) {
			sql += " and subCompany = ? ";
			values.add(subcompany);
		}
		if(voltage != null) {
			sql += " and voltage = ? ";
			values.add(voltage);
		}
		sql += " order by month";
		ret = dao.findByCondition(FaultFastRemove.class, sql, values.toArray());
		return ret;
	}
	/**
	 * 查询月度数据
	 * @param year 为null 返回长度为0的列表
	 * @param month 为null则查询本年所有月度数据
	 * @param subcompany 为null则查询所有公司
	 * @return
	 */
	public List<FaultFastRemove> queryMonthFaultFastRemoveByCondition(Integer year, Integer month, String subcompany, 
		Integer voltage, int unitType) {
		List<FaultFastRemove> ret = new ArrayList<>();
		if(year == null)
			return ret;
		List<Object> values = new ArrayList<>();
		String sql = "year = ? ";
		values.add(year);
		if(month != null) {
			sql += " and month = ? ";
			values.add(month);
		}else {
			sql += " and month is not null ";
		}
		if(StringUtils.isNotEmpty(subcompany)) {
			sql += " and subCompany = ? ";
			values.add(subcompany);
		}
		if(voltage != null) {
			sql += " and voltage = ? ";
			values.add(voltage);
		}
		sql += " and unit_type = ? ";
		values.add(unitType);
		sql += " order by month";
		ret = dao.findByCondition(FaultFastRemove.class, sql, values.toArray());
		return ret;
	}
	/**
	 * 查询月度数据
	 * @param year 为null 返回长度为0的列表
	 * @param month 为null则查询本年所有月度数据
	 * @param subcompany 为null则查询所有公司
	 * @return
	 */
	public List<FaultFastRemove> queryMonthFaultFastRemoveByCondition(Integer year, Integer month, String subcompany, 
		Integer voltage, int unitType, List<String> unit) {
		List<FaultFastRemove> ret = new ArrayList<>();
		if(year == null)
			return ret;
		List<Object> values = new ArrayList<>();
		String sql = "year = ? ";
		values.add(year);
		if(month != null) {
			sql += " and month = ? ";
			values.add(month);
		}else {
			sql += " and month is not null ";
		}
		if(StringUtils.isNotEmpty(subcompany)) {
			sql += " and subCompany = ? ";
			values.add(subcompany);
		}
		if(voltage != null) {
			sql += " and voltage = ? ";
			values.add(voltage);
		}
		sql += " and unit_type = ? ";
		values.add(unitType);
		sql += " order by month";
		ret = dao.findByCondition(FaultFastRemove.class, sql, values.toArray());
		List<FaultFastRemove> dataList = new ArrayList<FaultFastRemove>();//返回数据
		for(FaultFastRemove faultFastRemove : ret) {
			if(unit.contains(faultFastRemove.getSubCompany())) {
				dataList.add(faultFastRemove);
			}
		}
		return dataList;
	}
	
	/**
	 * 查询年度数据
	 * @param year 为null返回长度为0的列表
	 * @param subcompany 为null查询所有公司
	 * @return
	 */
	public List<FaultFastRemove> queryYearFaultFastRemoveByCondition(Integer year,String subcompany,Integer voltage) {
		List<FaultFastRemove> ret = new ArrayList<>();
		if(year == null)
			return ret;
		List<Object> values = new ArrayList<>();
		String sql = "year = ? and month is null ";
		values.add(year);
		if(StringUtils.isNotEmpty(subcompany)) {
			sql += " and subCompany = ? ";
			values.add(subcompany);
		}
		if(voltage != null) {
			sql += " and voltage = ? ";
			values.add(voltage);
		}
		sql += " order by year";
		ret = dao.findByCondition(FaultFastRemove.class, sql, values.toArray());
		return ret;
	}
	/**
	 * 查询年度数据
	 * @param year 为null返回长度为0的列表
	 * @param subcompany 为null查询所有公司
	 * @return
	 */
	public List<FaultFastRemove> queryYearFaultFastRemoveByCondition(Integer year, String subcompany, Integer voltage, 
		int unitType) {
		List<FaultFastRemove> ret = new ArrayList<>();
		if(year == null)
			return ret;
		List<Object> values = new ArrayList<>();
		String sql = "year = ? and month is null ";
		values.add(year);
		if(StringUtils.isNotEmpty(subcompany)) {
			sql += " and subCompany = ? ";
			values.add(subcompany);
		}
		if(voltage != null) {
			sql += " and voltage = ? ";
			values.add(voltage);
		}
		sql += " and unit_type = ? ";
		values.add(unitType);
		sql += " order by year";
		ret = dao.findByCondition(FaultFastRemove.class, sql, values.toArray());
		return ret;
	}
	/**
	 * 查询年度数据
	 * @param year 为null返回长度为0的列表
	 * @param subcompany 为null查询所有公司
	 * @return
	 */
	public List<FaultFastRemove> queryYearFaultFastRemoveByCondition(Integer year, String subcompany, Integer voltage, 
		int unitType, List<String> unit) {
		List<FaultFastRemove> ret = new ArrayList<>();
		if(year == null)
			return ret;
		List<Object> values = new ArrayList<>();
		String sql = "year = ? and month is null ";
		values.add(year);
		if(StringUtils.isNotEmpty(subcompany)) {
			sql += " and subCompany = ? ";
			values.add(subcompany);
		}
		if(voltage != null) {
			sql += " and voltage = ? ";
			values.add(voltage);
		}
		sql += " and unit_type = ? ";
		values.add(unitType);
		sql += " order by year";
		ret = dao.findByCondition(FaultFastRemove.class, sql, values.toArray());
		List<FaultFastRemove> dataList = new ArrayList<FaultFastRemove>();//返回数据
		for(FaultFastRemove faultFastRemove : ret) {
			if(unit.contains(faultFastRemove.getSubCompany())) {
				dataList.add(faultFastRemove);
			}
		}
		return dataList;
	}

}
